package com.recharge.common.enums;

import lombok.Getter;

/**
 * 操作日志类型枚举
 * @author kui
 * @date 2018/9/12
 */
@Getter
public enum OperationType {
    /**
     * 测试
     */
//    TEST_TEST("UserServiceImpl","getUserByName",0,"测试日志,不带参数的")
    ;

    /**
     * 操作类名
     */
    private String className;

    /**
     * 操作方法名
     */
    private String methodName;

    /**
     * 操作类型
     * 0: 未知
     * 1: 添加
     * 2: 删除
     * 3: 修改
     * 4: 查询
     */
    private int operationType;

    /**
     * 操作信息
     */
    private String description;

    /**
     * 模块名
     */
    private String moduleName;

    OperationType(String className, String methodName, int operationType, String description) {
        this.className = className;
        this.methodName = methodName;
        this.operationType = operationType;
        this.description = description;
        this.moduleName = String.format("%s::%s", className, methodName);
    }

    /**
     * 获取枚举对象
     * @param className 类名
     * @param methodName 方法名
     * @return 枚举对象
     */
    public static OperationType get(String className, String methodName){
        OperationType[] operationTypes = OperationType.values();
        for (OperationType operationType : operationTypes) {
            if (operationType.getClassName().equals(className) && operationType.getMethodName().equals(methodName)){
                return operationType;
            }
        }
        return null;
    }
}
